var memeryLi = document.getElementsByName("memeryLi");
function changePrice(obj, price) {
    document.getElementById("headPrice").innerText = price + ".0元";
    document.getElementById("grayPrice").innerText = price + ".0元";
    document.getElementById("totalPrice").innerText = "总计: " + price + ".0元";
    document.getElementById("memery").innerText = obj.children[0].value;

    for(let i = 0; i < memeryLi.length; i++){
        memeryLi[i].style.borderColor = "rgb(204, 204, 204)";
        memeryLi[i].removeAttribute("index");
    }
    obj.setAttribute("index", "true");
    obj.style.borderColor = "rgb(255, 103, 0)";
}
var colorLi = document.getElementsByName("colorLi");
function changeColor(obj, color) {

    for(let i = 0; i < colorLi.length; i++){
        colorLi[i].style.borderColor = "rgb(204, 204, 204)";
        colorLi[i].removeAttribute("index");
    }
    // alert(color)
    document.getElementById("indexColor").innerText = color;
    obj.setAttribute("index", "true");
    obj.style.borderColor = "rgb(255, 103, 0)";
}



let count = 0;
function bian() {
    count++;
    if (count % 2 != 0) {
        document.getElementById("heart").style.color = "red"
        let productId = parseInt(document.getElementById("productId").value);
        let productName = document.getElementById("productName").value;
        let productPig = document.getElementById("productPig").value;
        let price = document.getElementById("headPrice").innerText;
        let str = "";
        for(let i = 0; i < memeryLi.length; i++){
            if(memeryLi[i].getAttribute("index") == "true")
                str += memeryLi[i].innerText
        }
        str += " "
        for(let i = 0; i < colorLi.length; i++){
            if(colorLi[i].getAttribute("index") == "true")
                str += colorLi[i].innerText
        }
        $.post('/mi/personal_center/insert_like', {productId:productId, productName:productName, productPig:productPig, price:price, paraName:str});
    }
    if (count % 2 == 0) {
        let productId = parseInt(document.getElementById("productId").value);
        document.getElementById("heart").style.color = "#fff"
        $.post('/mi/personal_center/delete_like',{productId:productId});
    }
}



function heart_true() {
    //1代表已选中, 要从购物车中删除该商品
        let paraPrice = document.getElementById("grayPrice").innerText.substring(0, document.getElementById("grayPrice").innerText.length - 1);
        let proName = document.getElementById("proName");
        let productId = document.getElementById("productId");
        let para = proName.innerText + " ";
        // alert(str)
        let str = "";
        for(let i = 0; i < memeryLi.length; i++){
            if(memeryLi[i].getAttribute("index") == "true") {
                para += memeryLi[i].innerText.trim();
                str += memeryLi[i].innerText.trim();
            }
        }
        para += " ";
        if(para.indexOf("+") != -1){
            // alert(1111)
            para = para.replace('+', '%2B');
        }
        for(let i = 0; i < colorLi.length; i++){
            if(colorLi[i].getAttribute("index") == "true")
                para += colorLi[i].innerText.trim();
        }
        let status = 1;
        if(document.getElementById("heart").style.color == "red")
            status = 1;
        else
            status = 0;
        if(str != "") {
            $.post('/mi/personal_center/dealCollect', {productId: productId.value, status: status}, function (res) {
                count++;
                if (count % 2 != 0) {
                    document.getElementById("heart").style.color = "red"
                    }
                if (count % 2 == 0) {
                    document.getElementById("heart").style.color = "#fff"
                }
            });
        }
        else
            layer.tips('请选择商品参数后加入收藏', '#like');

}

